﻿
jQuery(document).ready(function()
{
    var openImage = "tv_open.gif";
    var closeImage = "tv_close.gif";

    //loading事件
    jQuery("iframe[id$='frmShowStudentList']").load(function()
    {
        var $ifram = jQuery(this);
        var div = $ifram.parents().children("div[id$='divLoading']").hide(); 
    });

    //展开事件
    jQuery("img[id$='imgExpend']").click(function()
    {
        var $imgExpend = jQuery(this);
        var controlKey = $imgExpend.attr("id").split("_")[0];
        var $trChildren = $imgExpend.parents("[id$='trParent']").next();
        var trDisplay = $trChildren.css("display");
        var $hidUrl = $trChildren.children("[ifram$='ifram']").children("[id$='hidUrl']");
        var $frmProducts = $trChildren.children("[ifram$='ifram']").children("iframe[id$='frmShowStudentList']");

        //显示\隐藏当前信息
        if (trDisplay == "none")
        {
            $trChildren.show();
            $imgExpend.attr("src", $imgExpend.attr("src").replace(closeImage, openImage));
            var url = $hidUrl[0].value + "&" + Math.random();
            $frmProducts.attr("src", url);
        }
        else
        {
            $trChildren.hide();
            $imgExpend.attr("src", $imgExpend.attr("src").replace(openImage, closeImage));
        }
        saveRepeaterList();
        //用于展开和收缩时如果页面定义ResizeContentFrame函数，则改变iframe大小
        //if ($.isFunction(window.ResizeContentFrame))
        //{
        //    ResizeContentFrame();
        //}
    });
    openRepeaterList(closeImage, openImage);

    //鼠标移上移出事件
    var $trParent = jQuery("tr[id$='trParent']");
    $trParent.mouseover(function()
    {
        jQuery(this).removeClass("Main_tMouseout");
        jQuery(this).addClass("Main_tMouseover");
    });
    $trParent.mouseout(function()
    {
        jQuery(this).removeClass("Main_tMouseover");
        jQuery(this).addClass("Main_tMouseout");
    });
});

//记录打开的节点
var saveRepeaterList = function()
{
    var openKey = "";
    jQuery("tr:visible[id$='trChildren']").each(function()
    {
        if (openKey != "") openKey += ",";
        openKey += jQuery(this).attr("id");
    });
    setCookie("TreeGrid", openKey);
}

//打开记录的节点
var openRepeaterList = function(closeImage, openImage)
{ 
    var openKey = getCookie("TreeGrid");
    if (openKey != null && openKey != "")
    {
        var keyValues = openKey.split(",");
        for (var i = 0; i < keyValues.length; i++)
        {
            var $trChildren = jQuery("#" + keyValues[i]);
            var $imgExpend = $trChildren.prev().find("img");
            if ($trChildren.attr("id") != null)
            {
                $trChildren.show();
                var $hidUrl = $trChildren.children("[ifram$='ifram']").children("[id$='hidUrl']");
                var $frmProducts = $trChildren.children("[ifram$='ifram']").children("iframe[id$='frmShowStudentList']");
                $frmProducts.attr("src", $hidUrl[0].value);
            }
            if ($imgExpend.attr("id") != null) $imgExpend.attr("src", $imgExpend.attr("src").replace(closeImage, openImage));
        }
    }
    //用于展开和收缩时如果页面定义ResizeContentFrame函数，则改变iframe大小
    //if ($.isFunction(window.ResizeContentFrame))
    //{
    //    ResizeContentFrame();
    //}
}

//表格鼠标变换样式
jQuery(document).ready(function()
{
    //鼠标移上移出事件
    var $trItem = jQuery("tr[id='trItem']");
    $trItem.mouseover(function()
    {
        jQuery(this).addClass("Main_tMouseover");
    });
    $trItem.mouseout(function()
    {
        jQuery(this).removeClass("Main_tMouseover");
    });
});